home *** CD-ROM | disk | FTP | other *** search
/ Quick PC 61 / Quick PC 61.iso / I386 / SASETUP.MSI / F77535_inc_debug.asp < prev    next >
Encoding:
Text File  |  2003-03-24  |  12.4 KB  |  697 lines

  1.  
  2. <%    '==================================================
  3.     ' Module:    inc_debug.asp
  4.     '
  5.     ' Synopsis:    Server Appliance Web Framework Error Handling
  6.     '
  7.     ' Copyright (c) Microsoft Corporation.  All rights reserved.
  8.     '================================================== 
  9. %>
  10.     
  11.  
  12. <%
  13. 'Server.ScriptTimeout = 300
  14. '
  15. ' Global variables for Error handling support
  16. '
  17. Const MAX_TRACEFILE_SIZE = 500000
  18. Const MINIMUM_SCRIPT_TIMEOUT = 300
  19.  
  20. '
  21. ' ReEntrancy check variable
  22. DIM SA_INSIDE_DEBUG
  23. SA_INSIDE_DEBUG = 0
  24.  
  25. ' Last error code. 
  26. ' DO NOT access this variable directly, use SA_GetLastError
  27. DIM SA_LASTERROR
  28.  
  29. ' Function executing during last error
  30. ' DO NOT access this variable, it's for internal use only
  31. DIM SA_LASTERROR_FUNCTION
  32.  
  33. ' Tracing options
  34. Const SA_TRACE_OUTPUT_NONE            = 0
  35. Const SA_TRACE_OUTPUT_HTML            = 1
  36. Const SA_TRACE_OUTPUT_FILE            = 2
  37.  
  38. '
  39. ' Debugging enabled, default is enabled.
  40. ' DO NOT access this variable, it's for internal use only.
  41. '
  42. ' This variable is set in LoadRuntimeOptions() which
  43. ' is called below. We default to enabled just in case
  44. ' LoadRuntimeOptions failes to initialize.
  45. DIM SA_DEBUG_ENABLED
  46. SA_DEBUG_ENABLED = 0
  47.  
  48. ' Tracing option, default is HTML
  49. ' DO NOT access this variable, it's for internal use only.
  50. '
  51. ' This variable is set in LoadRuntimeOptions() which
  52. ' is called below. We default to enabled just in case
  53. ' LoadRuntimeOptions failes to initialize.
  54. DIM SA_TRACE_OPTION
  55. SA_TRACE_OPTION = SA_TRACE_OUTPUT_NONE
  56.  
  57. ' Current Tracing output file
  58. ' DO NOT access this variable, it's for internal use only
  59. DIM SA_TRACE_FILE
  60.  
  61. '
  62. ' Global constant error codes
  63. Const gc_ERR_SUCCESS = 0
  64.  
  65.  
  66. SA_LASTERROR = gc_ERR_SUCCESS
  67.  
  68.  
  69. '
  70. ' Set the Runtime options
  71. '
  72. LoadRuntimeOptions()
  73.  
  74. '
  75. ' Set page level error handling
  76. '
  77. If (SA_DEBUG_ENABLED <> 0) Then
  78.     '
  79.     ' Debugging mode
  80.     '
  81.     On Error goto 0
  82. Else
  83.     '
  84.     ' Release mode
  85.     '
  86.     On Error Resume Next
  87. End If
  88.  
  89.  
  90. ' --------------------------------------------------------------
  91. ' Function:    
  92. '
  93. ' Synopsis:    
  94. '
  95. ' Arguments: 
  96. ' --------------------------------------------------------------
  97. Private Function LoadRuntimeOptions()
  98.     ON ERROR RESUME NEXT
  99.     Dim objRegistry
  100.     Dim dwDebugOption
  101.  
  102.     '
  103.     ' Prevent recursion into this module. Specifically, SA_TraceOut
  104.     SA_EnterDebugModule()
  105.  
  106.     '
  107.     ' Disable for now
  108.     '
  109.  
  110.     Set objRegistry = RegConnection()
  111.     If (NOT IsObject(objRegistry)) Then
  112.         SA_TraceOut "LoadRuntimeOptions", "RegConnection() failed " + "(" + Hex(Err.Number) + ")"
  113.         Exit Function
  114.     End If
  115.  
  116.     '
  117.     ' Fetch debugging flag
  118.     '
  119.     SA_DEBUG_ENABLED= GetRegkeyValue( objRegistry, _
  120.                                 "SOFTWARE\Microsoft\ServerAppliance\WebFramework",_
  121.                                 "Debug", CONST_DWORD)
  122.     If (SA_DEBUG_ENABLED <> 0) Then
  123.         '
  124.         ' Debugging mode
  125.         '
  126.         On Error goto 0
  127.     Else
  128.         '
  129.         ' Release mode
  130.         '
  131.         On Error Resume Next
  132.     End If
  133.  
  134.  
  135.     SA_TRACE_OPTION = GetRegkeyValue( objRegistry, _
  136.                                 "SOFTWARE\Microsoft\ServerAppliance\WebFramework",_
  137.                                 "TraceOption", CONST_DWORD)
  138.  
  139.     SA_TRACE_FILE = GetRegkeyValue( objRegistry, _
  140.                                 "SOFTWARE\Microsoft\ServerAppliance\WebFramework",_
  141.                                 "TraceFile", CONST_STRING)
  142.                                 
  143.     Dim iScriptTimeOut
  144.     iScriptTimeOut = GetRegkeyValue( objRegistry, _
  145.                                 "SOFTWARE\Microsoft\ServerAppliance\WebFramework",_
  146.                                 "ScriptTimeOut", CONST_DWORD)
  147.     If ( NOT IsNumeric(iScriptTimeOut) ) Then
  148.         iScriptTimeOut = MINIMUM_SCRIPT_TIMEOUT
  149.     ElseIf ( iScriptTimeOut < MINIMUM_SCRIPT_TIMEOUT ) Then
  150.         iScriptTimeOut = MINIMUM_SCRIPT_TIMEOUT
  151.     End If
  152.     Server.ScriptTimeout = CInt(iScriptTimeOut)
  153.     
  154.     SA_ExitDebugModule()
  155.  
  156.     Set objRegistry = nothing
  157.     
  158. End Function
  159.  
  160.  
  161.  
  162. ' --------------------------------------------------------------
  163. ' Function:    SA_EnterDebugModule
  164. '
  165. ' Synopsis:    Mark us as inside the debug module. This is used for
  166. '            reentrancy checks. We don't want to get caught in
  167. '            a recussion loop if we have an error inside this module.
  168. '
  169. ' Arguments: 
  170. ' --------------------------------------------------------------
  171. Private Function SA_EnterDebugModule()
  172.     SA_INSIDE_DEBUG = 1
  173. End Function
  174.  
  175. ' --------------------------------------------------------------
  176. ' Function:    SA_ExitDebugModule
  177. '
  178. ' Synopsis:    Mark us as exiting the debug module. This is used for
  179. '            reentrancy checks. We don't want to get caught in
  180. '            a recussion loop if we have an error inside this module.
  181. '
  182. ' Arguments: 
  183. ' --------------------------------------------------------------
  184. Private Function SA_ExitDebugModule()
  185.     SA_INSIDE_DEBUG = 0
  186. End Function
  187.  
  188. ' --------------------------------------------------------------
  189. ' Function:    SA_IsExecutingDebugModule
  190. '
  191. ' Synopsis:    Check to see if we are reentering this module
  192. '
  193. ' --------------------------------------------------------------
  194. Private Function SA_IsExecutingDebugModule()
  195.     SA_IsExecutingDebugModule = SA_INSIDE_DEBUG
  196. End Function
  197.  
  198. ' --------------------------------------------------------------
  199. ' Function:    
  200. '
  201. ' Synopsis:    
  202. '
  203. ' Arguments: 
  204. ' --------------------------------------------------------------
  205. Public Function SA_IsDebugEnabled()
  206.     SA_IsDebugEnabled = SA_DEBUG_ENABLED
  207. End Function
  208.  
  209.  
  210. ' --------------------------------------------------------------
  211. ' Function:    
  212. '
  213. ' Synopsis:    
  214. '
  215. ' Arguments: 
  216. ' --------------------------------------------------------------
  217. Public Function SA_EnableDebug(ByVal DebugEnabled)
  218.     SA_DEBUG_ENABLED = DebugEnabled
  219.     
  220.     Dim objRegistry
  221.     Dim rc
  222.     
  223.     Set objRegistry = RegConnection()
  224.     If (NOT IsObject(objRegistry)) Then
  225.         SA_TraceOut "SA_EnableDebug", "RegConnection() failed " + "(" + Hex(Err.Number) + ")"
  226.         Exit Function
  227.     End If
  228.     
  229.     rc = UpdateRegkeyValue( objRegistry, _
  230.                             "SOFTWARE\Microsoft\ServerAppliance\WebFramework",_
  231.                             "Debug", _
  232.                             DebugEnabled, _
  233.                             CONST_DWORD)
  234.  
  235.     Set objRegistry = nothing
  236.     
  237.     SA_EnableDebug = gc_ERR_SUCCESS
  238. End Function
  239.  
  240.  
  241. ' --------------------------------------------------------------
  242. ' Function:    
  243. '
  244. ' Synopsis:    
  245. '
  246. ' Arguments: 
  247. ' --------------------------------------------------------------
  248. Public Function SA_GetTraceOption()
  249.     SA_GetTraceOption = SA_TRACE_OPTION
  250. End Function
  251.  
  252.  
  253. ' --------------------------------------------------------------
  254. ' Function:    SA_SetDebugOption
  255. '
  256. ' Synopsis:    Set the debugging option.
  257. '
  258. ' Arguments: [in] Option - Debugging option to use which can be a combination of
  259. '            SA_TRACE_OUTPUT_HTML Debugging errors emitted with HTML response
  260. '            SA_TRACE_OUTPUT_FILE Debugging errors emitted to output file
  261. ' --------------------------------------------------------------
  262. Public Function SA_SetDebugOption(ByVal DebugOption)
  263.     SA_TRACE_OPTION = DebugOption
  264.     
  265.     Dim objRegistry
  266.     Dim rc
  267.     
  268.     Set objRegistry = RegConnection()
  269.     If (NOT IsObject(objRegistry)) Then
  270.         SA_TraceOut "SA_SetDebugOption", "RegConnection() failed " + "(" + Hex(Err.Number) + ")"
  271.         Exit Function
  272.     End If
  273.     
  274.     rc = UpdateRegkeyValue( objRegistry, _
  275.                             "SOFTWARE\Microsoft\ServerAppliance\WebFramework",_
  276.                             "TraceOption", _
  277.                             DebugOption, _
  278.                             CONST_DWORD)
  279.  
  280.     Set objRegistry = nothing
  281.     
  282.     SA_SetDebugOption = gc_ERR_SUCCESS
  283. End Function
  284.  
  285.  
  286. ' --------------------------------------------------------------
  287. ' Function:    
  288. '
  289. ' Synopsis:    
  290. '
  291. ' Arguments: 
  292. ' --------------------------------------------------------------
  293. Public Function SA_GetTraceOutputFile()
  294.     SA_GetTraceOutputFile = SA_TRACE_FILE
  295. End Function
  296.  
  297.  
  298. ' --------------------------------------------------------------
  299. ' Function:    SA_SetDebugOutputFile
  300. '
  301. ' Synopsis:    Set the debugging output file
  302. '
  303. ' Arguments: [in] File - Filename to receive debugging output
  304. ' --------------------------------------------------------------
  305. Public Function SA_SetDebugOutputFile(ByVal File)
  306.     SA_TRACE_FILE = File
  307.  
  308.     Dim objRegistry
  309.     Dim rc
  310.     
  311.     Set objRegistry = RegConnection()
  312.     If (NOT IsObject(objRegistry)) Then
  313.         SA_TraceOut "SA_SetDebugOutputFile", "RegConnection() failed " + "(" + Hex(Err.Number) + ")"
  314.         Exit Function
  315.     End If
  316.     
  317.     rc = UpdateRegkeyValue( objRegistry, _
  318.                             "SOFTWARE\Microsoft\ServerAppliance\WebFramework",_
  319.                             "TraceFile", _
  320.                             File, _
  321.                             CONST_STRING)
  322.  
  323.     Set objRegistry = nothing
  324.  
  325.     
  326.     SA_SetDebugOutputFile = gc_ERR_SUCCESS
  327. End Function
  328.  
  329.  
  330. ' --------------------------------------------------------------
  331. ' Function:    
  332. '
  333. ' Synopsis:    
  334. '
  335. ' Arguments: 
  336. ' --------------------------------------------------------------
  337. Function SA_ClearTraceLog()
  338.  
  339.  
  340.  
  341.  
  342.  
  343.  
  344.  
  345.  
  346.  
  347.  
  348.  
  349.  
  350.  
  351.  
  352.  
  353.  
  354.  
  355.  
  356.  
  357.  
  358.  
  359.  
  360.  
  361.  
  362.  
  363.  
  364.  
  365.  
  366.  
  367.  
  368.  
  369.  
  370.  
  371. End Function
  372.  
  373.  
  374. ' --------------------------------------------------------------
  375. ' Function:    
  376. '
  377. ' Synopsis:    
  378. '
  379. ' Arguments: 
  380. ' --------------------------------------------------------------
  381. Function SA_ShowTraceLog()
  382.  
  383.  
  384.  
  385.  
  386.  
  387.  
  388.  
  389.  
  390.  
  391.  
  392.  
  393.  
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.  
  401.  
  402.  
  403.  
  404.  
  405.  
  406.  
  407.  
  408.  
  409.  
  410.  
  411.  
  412.  
  413.  
  414.  
  415.  
  416.  
  417.  
  418.  
  419.  
  420.  
  421.  
  422.  
  423.  
  424.  
  425.  
  426.  
  427.  
  428.  
  429.  
  430.  
  431. End Function
  432.  
  433.  
  434. ' --------------------------------------------------------------
  435. ' Function:    
  436. '
  437. ' Synopsis:    
  438. '
  439. ' Arguments: 
  440. ' --------------------------------------------------------------
  441. Function SA_ShowRuntimeOptions()
  442.  
  443.  
  444.  
  445.  
  446.  
  447.  
  448.  
  449.  
  450.  
  451.  
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459.  
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466.  
  467.  
  468.  
  469.  
  470. End Function
  471.  
  472.  
  473. ' --------------------------------------------------------------
  474. ' Function:    SA_TraceOut
  475. '
  476. ' Synopsis:    Output tracing information
  477. '
  478. ' Arguments: [in] Module - Module/Function issuing the tracing message
  479. '            [in] Message - Message to be output
  480. ' --------------------------------------------------------------
  481. Public Function SA_TraceOut(ByVal  Module, ByVal Message)
  482.  
  483.  
  484.  
  485.  
  486.  
  487.  
  488.  
  489.  
  490.  
  491.     SA_TraceOut = gc_ERR_SUCCESS
  492. End Function
  493.  
  494. ' --------------------------------------------------------------
  495. ' Function:    SA_TraceErrorOut
  496. '
  497. ' Synopsis:    Output tracing information for error conditions. Errors are
  498. '            flaged with the keyword ISSUE.
  499. '
  500. ' Arguments: [in] Module - Module/Function issuing the tracing message
  501. '            [in] Message - Message to be output
  502. ' --------------------------------------------------------------
  503. Public Function SA_TraceErrorOut(ByVal  Module, ByVal Message)
  504.     Dim rc
  505.     
  506.     rc = SA_TraceOut("ISSUE: " + Module, Message)
  507.     
  508.     SA_TraceErrorOut = rc
  509. End Function
  510.  
  511.  
  512. ' --------------------------------------------------------------
  513. ' Function:    SA_SetLastError
  514. '
  515. ' Synopsis:    Set the last error code.
  516. '
  517. ' Arguments: [in] ErrorCode - Error code
  518. '            [in] FunctionName - Name of function where error occured
  519. ' --------------------------------------------------------------
  520. Public Function SA_GetLastError()
  521.     SA_GetLastError = SA_LASTERROR
  522. End Function
  523.  
  524.  
  525. ' --------------------------------------------------------------
  526. ' Function:    SA_SetLastError
  527. '
  528. ' Synopsis:    Set the last error code.
  529. '
  530. ' Arguments: [in] ErrorCode - Error code
  531. '            [in] FunctionName - Name of function where error occured
  532. '
  533. ' Returns:    The error code specified in ErrorCode parameter
  534. ' --------------------------------------------------------------
  535. Public Function SA_SetLastError(ByVal ErrorCode, ByVal FunctionName )
  536.     SA_LASTERROR = ErrorCode
  537.     SA_LASTERROR_FUNCTION = FunctionName
  538.     Err.Number = ErrorCode
  539.     
  540.     SA_SetLastError = ErrorCode
  541.  
  542.     '
  543.     ' If we had an error then emit trace output. An error is
  544.     ' any error code other than gc_ERR_SUCCESS.
  545.     '
  546.     If ( ErrorCode <> gc_ERR_SUCCESS ) Then
  547.         SA_InternalTraceOut "ISSUE: "+FunctionName, CStr(ErrorCode)
  548.     End If
  549.     
  550. End Function
  551.  
  552.  
  553. ' --------------------------------------------------------------
  554. ' Function:    SA_SetLastError
  555. '
  556. ' Synopsis:    Set the last error code.
  557. '
  558. ' Arguments: [in] ErrorCode - Error code
  559. '            [in] FunctionName - Name of function where error occured
  560. ' --------------------------------------------------------------
  561. Public Function SA_ClearError()
  562.     SA_LASTERROR = gc_ERR_SUCCESS
  563.     Err.Number = 0
  564.     SA_ClearError = gc_ERR_SUCCESS
  565. End Function
  566.  
  567.  
  568. ' --------------------------------------------------------------
  569. ' Function:    _SA_InternalTraceOut
  570. '
  571. ' Synopsis:    Internal function to handle output tracing.
  572. '
  573. ' Arguments: [in] Module - Module/Function issuing the tracing message
  574. '            [in] Message - Message to be output
  575. ' --------------------------------------------------------------
  576. Private Function SA_InternalTraceOut(ByVal  Module, ByVal Message)
  577.  
  578.  
  579.  
  580.  
  581.  
  582.  
  583.  
  584.  
  585.  
  586.  
  587.  
  588.  
  589.  
  590.  
  591.  
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598.  
  599.  
  600.  
  601.  
  602.  
  603.  
  604.  
  605.  
  606.  
  607.  
  608.  
  609.  
  610.  
  611.  
  612.  
  613.  
  614.  
  615.  
  616.  
  617.  
  618.  
  619.  
  620.  
  621.  
  622.  
  623.  
  624.  
  625.  
  626.  
  627.  
  628.  
  629.  
  630.  
  631.  
  632.  
  633.  
  634.  
  635.  
  636.  
  637.  
  638.  
  639.  
  640.  
  641.  
  642.  
  643.  
  644.  
  645.  
  646.  
  647.  
  648.  
  649.  
  650.  
  651.  
  652.  
  653.  
  654.  
  655.     SA_InternalTraceOut = gc_ERR_SUCCESS
  656. End Function
  657.  
  658. %>
  659.  
  660.